package cn.biplam.front.callback;

import cn.biplam.common.tools.TOOLS;
import cn.biplam.common.wrapper.ErrorMessage;
import cn.biplam.common.wrapper.Result;
import cn.biplam.common.wrapper.UserInfo;
import cn.biplam.front.html.base.HtmlWindow;
import cn.biplam.front.template.base.Anchor;
import cn.biplam.front.template.base.Text;

/**
 * 数据探查—字段描述绑定器-用于显示格式为"物理名称(逻辑名称)"
 * @author XiaoRuxing 2009-7-22下午04:14:04
 * @version 1.0
 */
public class FieldDescCallback implements CallBack{

	/** 主信息字段 */
	private String sFieldName;
	/** 说明信息字段 */
	private String sDescFieldName;
	private boolean isAnchor = false;
	
	/**
	 * 
	 * @param sFieldNam      主信息字段
	 * @param sDescFieldName 说明信息字段
	 */
	public FieldDescCallback(String sFieldName
			,String sDescFieldName){
		this.sFieldName = sFieldName;
		this.sDescFieldName = sDescFieldName;
	}
	
	/**
	 * 
	 * @param sFieldNam      主信息字段
	 * @param sDescFieldName 说明信息字段
	 */
	public FieldDescCallback(String sFieldName
			,String sDescFieldName,boolean isAnchor){
		this.sFieldName = sFieldName;
		this.sDescFieldName = sDescFieldName;
		this.isAnchor = isAnchor;
	}
	
	public HtmlWindow[] getGroup(Result data, String homeUrl, UserInfo mUser)
	throws ErrorMessage {
		HtmlWindow[] total = new HtmlWindow[1];
		String result = data.getString(sFieldName)+
		TOOLS.getBracketDesc(data.getString(sDescFieldName));
		HtmlWindow typeDesc = null;
		if(isAnchor){
			typeDesc = new Anchor(null,result.toString(),null,"查看字段信息").get();
		}else{
			Text text=new Text(result);
			typeDesc=text.get();
			typeDesc.setLength(TOOLS.getPxLength(text.getLength()));
		}
		total[0] = typeDesc ;
		return total;
	}
}
